package com.wh.hotel.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.base.Preconditions;
import com.wh.common.annotation.ResultLog;
import com.wh.common.enums.MethodTypeEnum;
import com.wh.common.vo.Result;
import com.wh.hotel.model.HotelBaseInfo;
import com.wh.hotel.service.HotelBaseService;
import com.wh.hotel.vo.HotelBaseInfoVo;
import com.wh.hotel.vo.HotelQueryVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author luweije
 */
@RequestMapping("/hotel/base")
@RestController
@Slf4j
public class HotelBaseController {

    @Resource
    private HotelBaseService hotelBaseService;

    /**
     * 新增酒店
     *
     * @param param
     * @return
     */
    @PostMapping("/add")
    @ResultLog(name = "HotelBaseController.addHotel", methodType = MethodTypeEnum.HTTP_UP)
    public Result<HotelBaseInfo> addHotel(@RequestBody HotelBaseInfoVo param) {
        Preconditions.checkNotNull(param.getOpenTime(), "开业时间不能空");
        Preconditions.checkArgument(StringUtils.isNotBlank(param.getHotelName()), "酒店名称不能空");
        HotelBaseInfo hotelBaseInfo = hotelBaseService.addHotel(param);
        if (hotelBaseInfo != null) {
            return Result.successResponse(hotelBaseInfo);
        }
        return Result.failResponse("新增酒店失败");
    }

    /**
     * 上下架酒店
     *
     * @param param
     * @return
     */
    @PostMapping("/operateStatus")
    @ResultLog(name = "HotelBaseController.operateStatus", methodType = MethodTypeEnum.HTTP_UP)
    public Result<Boolean> operateStatus(@RequestBody HotelBaseInfoVo param) {
        Preconditions.checkNotNull(param.getId(), "操作ID不能空");
        Preconditions.checkNotNull(param.getOperateType(), "操作类型不能空");
        if (hotelBaseService.operateStatus(param)) {
            return Result.successResponse();
        }
        return Result.failResponse("上下架酒店失败");
    }

    /**
     * 编辑酒店基础信息
     *
     * @param param
     * @return
     */
    @PostMapping("/edit")
    @ResultLog(name = "HotelBaseController.edit", methodType = MethodTypeEnum.HTTP_UP)
    public Result<Boolean> edit(@RequestBody HotelBaseInfoVo param) {
        Preconditions.checkNotNull(param.getId(), "操作ID不能空");
        if (hotelBaseService.editHotel(param)) {
            return Result.successResponse();
        }
        return Result.failResponse("编辑酒店基础信息失败");
    }


    /**
     * 查询酒店列表
     *
     * @param hotelQueryVo
     * @return
     */
    @PostMapping("/list")
    @ResultLog(name = "HotelBaseController.list", methodType = MethodTypeEnum.HTTP_UP)
    public Result<IPage<HotelBaseInfoVo>> list(@RequestBody HotelQueryVo hotelQueryVo) {
        return Result.successResponse(hotelBaseService.list(hotelQueryVo));
    }

    /**
     * 查询酒店详情
     *
     * @param hotelQueryVo
     * @return
     */
    @PostMapping("/detail")
    @ResultLog(name = "HotelBaseController.detail", methodType = MethodTypeEnum.HTTP_UP)
    public Result<HotelBaseInfoVo> detail(@RequestBody HotelQueryVo hotelQueryVo) {
        Preconditions.checkNotNull(hotelQueryVo.getId(), "酒店ID不能空");
        return Result.successResponse(hotelBaseService.detail(hotelQueryVo));
    }
}
